package org.ytor.core.sqlflow.dsl.eval.function.support;

import org.ytor.common.util.Colls;
import org.ytor.common.util.Numbers;
import org.ytor.common.util.id.Ids;
import org.ytor.core.sqlflow.dsl.eval.function.Func;
import org.ytor.core.sqlflow.dsl.expr.node.support.FunctionCallNode;

import java.util.List;
import java.util.Objects;

/**
 * created by yangtong on 2025/8/7 00:19:32
 * <br/>
 * 乘法函数
 */
public class Mul implements Func {
    @Override
    public Boolean support(FunctionCallNode functionCallNode) {
        return functionCallNode.functionName.equalsIgnoreCase("mul");
    }

    @Override
    public Object call(List<Object> args) {
        args = args.stream().filter(Objects::nonNull).toList();
        if (Colls.isEmpty(args)) {
            return null;
        }

        Number num = Numbers.toNumber(args.getFirst().toString());
        for (int i = 1; i < args.size(); i++) {
            num = Numbers.mul(Numbers.toNumber(args.get(i).toString()), num);
        }

        return num;
    }

}